<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" href="/css/logicss/common.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/print.css" rel="stylesheet" media = "print"/>
<link type="text/css" href="/css/logicss/utils.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/e24m.css" rel="stylesheet" />
<link type="text/css" href="/css/logicss/dark.css" rel="stylesheet" />
<style type="text/css" media="screen">
        @import '/css/logicss/utils.css';
        @import '/css/logicss/mix.css';
        @import '/css/logicss/small.css';
        @import '/css/logicss/e24m.css';
        @import '/css/logicss/dark.css';
        @import '/css/logicss/common.css';
        #nav-site { margin-top: 1.75em; }
    </style>
<script type="text/javascript">
function isDigit(s) 
{ 
    var patrn=/^\d+(\.\d+)?$/; 
	//var patrn = /^[0-9]{1,20}$/;
	if (!patrn.exec(s)) return false ;
	return true ;
}

	
	



var obj = null;
function ab()
{
	var label = document.getElementById(obj);
	var str = document.getElementById("string");
	label.innerText = str.value;
	obj = null;
}

function edit(id)
{ 
	if(obj!=id)
	{ 
		if(obj!=null)
		{ab();}
		obj = id;
		var lable = document.getElementById(id);
		var l = lable.innerText;
		lable.innerHTML = "<input type='text' id='string' onblur='ab()'></input>";
		var str = document.getElementById("string");
		str.focus();
		str.value=l;
	}
}

function save()
{
	if(obj!=null)
	{ab();}
	var form = document.getElementById("resetData");
	form.nutrimentID.value = document.getElementById("1").value;
	form.classificationID.value = document.getElementById("2").value;
	form.max.value = document.getElementById("3").innerText;
	form.min.value = document.getElementById("4").innerText;
	form.description.value = document.getElementById("5").innerText;

	//if(!(isDigit(form.max.value)&&isDigit(form.min.value)&&form.max.value>form.min.value))
	//{
	//	alert("输入数据错误，请重新出入");
	//	return;
	//}
	
	form.submit();
	alert("修改成功");
	form.submit();
}


function erase()
{
	var form = document.getElementById("deleteData");
	alert(form.id.value);
	form.submit();
}


function checkForm()
{
	return true;
}


</script>
<title>Untitled Document</title>
</head>
<body id="page-home" style="background: url(/images/bg.jpg);">
<div id="contanier" class="content grid">
<div>
<div id="section" class="first col w5">
<img id = "logo" alt='logo' src='/images/logos/logo_small.jpg' width=80 height=40/>
</div>
<div id ="content-head" class="last col w6" >
<ol class="h-list" style="margin-top:18px">

<%	
Boolean admin = (Boolean)session.getAttribute("admin");

if(admin!=null)
{
if(admin.booleanValue()==true)
{
out.print("<li><a href='#' onclick='save()'>保存</a></li>");
out.print("<li><a href='#' onclick='erase()'>删除</a></li>");
}
}

%>
</ol>
</div>
</div>
<hr/>

</div>

<div id ="content-main" class="content grid" >
<div class="first col w5">
<ol class="v-list" style="text-align:left;">
<li><a >营养素：</a></li>
<li><a >标准：</a></li>
<li><a >Max：</a></li>
<li><a >Min：</a></li>
<li><a >描述：</a></li>
</ol>
</div>

<div class="last col w5">
<ol class="v-list" style="text-align:left;">
<%@ page import="java.util.List" %>
<%@ page import="db.nutriment.Nutriment" %>
<%@ page import="db.standard.classification.Classification" %>
<%@ taglib uri="/WEB-INF/tld/list-taglib.tld" prefix="tj" %>
<% 
String nutriment = (String)request.getAttribute("nutriment");
String cl = (String)request.getAttribute("classification");
String max = (String)request.getAttribute("max");
String min = (String)request.getAttribute("min");
String des = (String)request.getAttribute("description");
String id = (String)request.getAttribute("id");
@SuppressWarnings("unchecked")
List<Nutriment> nutriments = (List<Nutriment>)request.getAttribute("nutriments");
@SuppressWarnings("unchecked")
List<Classification> classifications = (List<Classification>)request.getAttribute("classifications");

%>
<li><tj:list id='1' list='${nutriments}' defaultId = '<%=nutriment %>'></tj:list></li>
<li><tj:list id='2' list='${classifications}' defaultId = '<%=cl %>'></tj:list></li>
<%
out.print("<li><a id='3' onclick='edit(this.id)' href='#'>"+max+"</a></li>");
out.print("<li><a id='4' onclick='edit(this.id)' href='#'>"+min+"</a></li>");
out.print("<li><a id='5' onclick='edit(this.id)' href='#'>"+des+"</a></li>");
%>
</ol></div>
<form method = "post" id ="resetData" action = "/standard/resetStandard.do">
<%
     out.print("<input type='hidden' name='standardID' value= '"+id+"' /> "); 
%>
<input type = 'hidden' name='nutrimentID'/>
<input type = 'hidden' name='classificationID'/>
<input type = 'hidden' name='max'/>
<input type = 'hidden' name='min'/>
<input type = 'hidden' name='description'/>
</form>


<form method = "post" id = "deleteData" action="/standard/removeStandard.do">
<%
     out.print("<input type='hidden' name='standardID' value= '"+id+"' /> "); 
%>
</form>

</div>
</body>
</html>